package test;


import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;

import model.Item;

import service.CatalogRemote;



public class CatalogTestClient {
	
	public static void main(final String[] args) throws Exception {

		System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		System.setProperty(Context.PROVIDER_URL, "localhost:1099");
		System.setProperty(Context.URL_PKG_PREFIXES,
				"org.jboss.naming:org.jnp.interfaces");

		System.out.println("lookup Catalog/remote ");
		
		CatalogRemote catalogstateless = (CatalogRemote) new InitialContext()
				.lookup("Catalog/remote");
		
		
		Item i1= catalogstateless.create();
		i1.setName("foobar");
		i1.setDescription("foobar");
		i1.setPrice(100.50);
		catalogstateless.save(i1);
		Item i2= catalogstateless.create();
		i2.setName("barfoo");
		i2.setDescription("foobar");
		i2.setPrice(200.50);
		catalogstateless.save(i2);
		Item i3= catalogstateless.create();
		i3.setName("barbaz");
		i3.setDescription("foobar");
		i3.setPrice(300.50);
		catalogstateless.save(i3);
		Item i4= catalogstateless.create();
		i4.setName("zoobar");
		i4.setDescription("foobar");
		i4.setPrice(400.50);
		catalogstateless.save(i4);
		
		List<Item> items = catalogstateless.getItems(1,3);
		if (items != null) {
			for (Item item : items) {
				System.out.println("item " + item.getName());
				
			}
		} else {
			System.out.println("Aucun item");
		}		

	}

}
